/*=========================================================================
Elite College as Engines of Upward Mobility: Evidence from Colombia's Ser Pilo Paga
Authors: Juliana Londoño-Vélez, Catherine Rodriguez, Fabio Sánchez
and Luis Esteban Álvarez-Arango

Creation date: June 6th, 2025
--------------------------------------------------------------------------
Figures A3a, A3b, A6a, A8a and A9a
=========================================================================*/

use "${data}/data_RD", clear
keep if icfes_per==20142
glo cond_saber11 "eligible_sisben==1"
glo cond_sisben	"eligible_saber11==1"
glo lim_saber11	40
glo lim_sisben 20

cap drop mean_include*
cap drop cut_saber_11 
cap drop cut_sisben
gegen cut_saber11=cut(running_saber11), at(-100(2)100)
gegen mean_include_saber11 = tag(cut_saber11) if eligible_sisben==1
gegen cut_sisben=cut(running_sisben), at(-40(1)40)
gegen mean_include_sisben = tag(cut_sisben) if eligible_saber11==1

rdrobust beneficiary_spp running_saber11 if ${cond_saber11}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_saber11) ) /(`bw')) * (abs(running_saber11) < (`bw')) )
cap drop bin
gegen bin =  mean(beneficiary_spp) if ${cond_saber11}, by(cut_saber11)
twoway 	(lfit beneficiary_spp running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 < 0, sort lcolor(black) ) (lfit beneficiary_spp running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 >= 0, sort lcolor(black) ) (scatter bin cut_saber11 if mean_include_saber11==1 & abs(running_saber11)<${lim_saber11}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-40(20)40) ylab(0(0.2)1) xtitle(Distance to SABER 11 cutoff) caption(Sample restricted to low-SES students., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/FigA3a.pdf", replace 

rdrobust beneficiary_spp running_sisben if ${cond_sisben}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_sisben) ) /(`bw')) * (abs(running_sisben) < (`bw')) )
cap drop bin
gegen bin =  mean(beneficiary_spp) if ${cond_sisben}, by(cut_sisben)
twoway 	(lfit beneficiary_spp running_sisben [pw=kw] if abs(running_sisben)<`bw' & ${cond_sisben} & running_sisben < 0, sort lcolor(black) ) (lfit beneficiary_spp running_sisben [pw=kw] if abs(running_sisben)<`bw' & ${cond_sisben} & running_sisben >= 0, sort lcolor(black) ) (scatter bin cut_sisben if mean_include_sisben==1 & abs(running_sisben)<${lim_sisben}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-20(10)20) ylab(0(0.2)1) xtitle(Distance to SISBEN cutoff) caption(Sample restricted to SABER 11-eligible individuals., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/FigA3b.pdf", replace 

rdrobust score_saberpro_5 running_sisben if ${cond_sisben}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_sisben) ) /(`bw')) * (abs(running_sisben) < (`bw')) )
cap drop bin
gegen bin =  mean(score_saberpro_5) if ${cond_sisben}, by(cut_sisben)
twoway 	(lfit score_saberpro_5 running_sisben [pw=kw] if abs(running_sisben)<`bw' & ${cond_sisben} & running_sisben < 0, sort lcolor(black) ) (lfit score_saberpro_5 running_sisben [pw=kw] if abs(running_sisben)<`bw' & ${cond_sisben} & running_sisben >= 0, sort lcolor(black) ) (scatter bin cut_sisben if mean_include_sisben==1 & abs(running_sisben)<${lim_sisben}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-20(10)20) ylab(0(0.2)1) xtitle(Distance to SISBEN cutoff) caption(Sample restricted to SABER 11-eligible individuals., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/FigA6a.pdf", replace 

rdrobust work_9 running_saber11 if ${cond_saber11}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_saber11) ) /(`bw')) * (abs(running_saber11) < (`bw')) )
cap drop bin
gegen bin =  mean(work_9) if ${cond_saber11}, by(cut_saber11)
twoway 	(lfit work_9 running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 < 0, sort lcolor(black) ) (lfit work_9 running_saber11 [pw=kw] if abs(running_saber11)<`bw' & ${cond_saber11} & running_saber11 >= 0, sort lcolor(black) ) (scatter bin cut_saber11 if mean_include_saber11==1 & abs(running_saber11)<${lim_saber11}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-40(20)40) ylab(0(0.2)1) xtitle(Distance to SABER 11 cutoff) caption(Sample restricted to low-SES students., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/FigA8a.pdf", replace 

rdrobust mw_9 running_sisben if ${cond_sisben}, masspoints(off) 
local bw=e(h_l)
cap drop kw
gen kw = ( (( (`bw') - abs(running_sisben) ) /(`bw')) * (abs(running_sisben) < (`bw')) )
cap drop bin
gegen bin =  mean(mw_9) if ${cond_sisben}, by(cut_sisben)
twoway 	(lfit mw_9 running_sisben [pw=kw] if abs(running_sisben)<`bw' & ${cond_sisben} & running_sisben < 0, sort lcolor(black) ) (lfit mw_9 running_sisben [pw=kw] if abs(running_sisben)<`bw' & ${cond_sisben} & running_sisben >= 0, sort lcolor(black) ) (scatter bin cut_sisben if mean_include_sisben==1 & abs(running_sisben)<${lim_sisben}, mc(black) ms(O) msize(small)), xline(0, lcolor(red) lpattern(dash)) xsize(8) xlab(-20(10)20) ylab(0(0.2)2) xtitle(Distance to SISBEN cutoff) caption(Sample restricted to SABER 11-eligible individuals., size(small)) legend(off) graphregion(color(white)) ytitle("")
graph export "${outcomes}/FigA9a.pdf", replace 

